package myky.com.doctorapp.wight;

import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import myky.com.doctorapp.R;

/**
 * Description:
 *
 * @author wuyangwuyang
 * Created by 2019/3/1 on 16:48
 */
public class LoadingDialog extends DialogFragment {


    public interface OnCancelListener {

        void onCancel();
    }

    public OnCancelListener cancelListener;

    public OnCancelListener getCancelListener() {
        return cancelListener;
    }

    public void setCancelListener(OnCancelListener cancelListener) {
        this.cancelListener = cancelListener;
    }

    String msg = "";

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.loading_dialog, null);
        TextView title = (TextView) view.findViewById(R.id.loading_msg);
        title.setText(msg);
        Dialog dialog = new Dialog(getActivity(), R.style.dialog);
        dialog.setContentView(view);
        return dialog;
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if(cancelListener!=null){

        cancelListener.onCancel();
        }
    }

    @Override
    public void onCancel(DialogInterface dialog) {
        super.onCancel(dialog);
        if(cancelListener!=null){

            cancelListener.onCancel();
        }
    }

    @Override
    public void show(android.app.FragmentManager manager, String tag) {
        if (tag != null) {
            msg = tag;
        }
        if (!this.isAdded()) {
            try {
                super.show(manager, tag);
            } catch (Exception e) {
            }
        }
    }

    @Override
    public void dismiss() {
        try {
            super.dismiss();
        } catch (Exception e) {
        }

    }
}
